layui.config({
    base : "../../js/"
}).extend({
    "jqCommon" : "jqCommon"
})
layui.use(['form','layer','upload','jqCommon'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
        jqcommon = layui.jqCommon;
        upload = layui.upload;

    form.on("submit(updateUser)",function(data){
        var type = $(".type").val();
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            type: "PUT",
            url:  "http://mini.yantaibaixing.cn/users",
            data: {"id":$(".id").val(),"name":$(".name").val(),"phone":$(".phone").val(),"pPhone":$(".pPhone").val(),"bankName":$(".bankName").val(),"bankCardNo":$(".bankCardNo").val(),"shopName":$(".shopName").val(),"discount":$(".discount").val(),"shopAdress":$(".shopAdress").val(),"shopImage":$(".shopImageInput").val(),"longitude":$(".longitude").val(),"latitude":$(".latitude").val(),"type":$(".type").val()},
            dataType: "JSON",
            success: function (data) {
                if(data.success){
                    setTimeout(function(){
                        top.layer.close(index);
                        top.layer.msg("修改用户信息成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    },1000);
                }else {
                    if(data.code == 513102){
                        layer.msg("邀请人不存在，请检查手机号是否正确！");
                    }
                }
            }
        });
        return false;
    })

    //执行实例
    var uploadInst = upload.render({
        elem: '#files' //绑定元素
        ,url: 'http://mini.yantaibaixing.cn/files' //上传接口
        ,done: function(res){
            //上传完毕回调
            console.log(res);
            $(".shopImagePreview").attr("href","http://static.yantaibaixing.cn/"+res.datas).text("【点我预览】");    //商户照片
            $(".shopImageInput").val(res.datas);    //商户照片隐藏域
            layer.msg("上传图片成功,点击可预览");
        }
        ,error: function(){
            //请求异常回调
        }
    });

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})